package com.jh.baseball;

import java.util.Scanner;

public class BaseBall 
{
	int strike = 0;
	int ball = 0;
	int out = 0;



	public int[] comBall()
	{
		int[] comBal = new int[3];
		int count = 0;

		while (count < 3) 
		{
			int combal = random();
			if (!isOverlap(comBal,combal)) 
			{
				comBal[count++] = combal;
			}
		}
		return comBal;
	}

	public boolean isOverlap(int[] a,int b)
	{
		boolean isC = false;
		for (int i = 0; i < a.length; i++) 
		{
			if (a[i]==b) 
			{
				isC = true;
			}
		}
		return isC;
	}

	public int random()
	{
		int random = 0;

		random = (int)(Math.random()*9+1);

		return random;
	}

	public int[] input(int array, int start, int end)
	{
		int[] userBal = new int[array];
		int count = 0;

		while (true) {
			try {
				System.out.println("0~9 사이의 숫자 하나를 입력해 주세요");
				Scanner sc = new Scanner(System.in);
				
				
				int scInt = sc.nextInt();
				
				

				if (array >= start && array <= end) {
					userBal[count++] = scInt;
				} else {
					System.out.println("0~9 사이에 숫자만 넣으라고 했지?! 생캬");
				}

				if (count >= array) 
				{
					System.out.println("숫자 입력이 완료 되었습니다.");
					break;
				}
			} catch (Exception e) {
				System.out.println("뭐시여? 숫자가 아니잖여? 뒤XXX??");
			}
		}
		return userBal;
	}


	public boolean isCheck(int[] userB)
	{
		boolean isC = false;

		for (int i = 0; i < userB.length; i++) 
		{
			for (int j = 0; j < userB.length; j++) 
			{
				if (i!=j && userB[i]==userB[j]) 
				{
					isC = true;
				}
			}
		}
		return isC;
	}

	public void compare()
	{
		int[] c = comBall();

		int gameCount = 0;
		while (true) {
			
			int[] u = input(3,1,9);
			gameCount ++;
			for (int i = 0; i < c.length; i++) {
				for (int j = 0; j < u.length; j++) {
					if (i == j &&c[i] == u[j] ) {
						strike += 1;

					} else if (c[i] == u[j]) {
						ball += 1;
					}
				}
			}

			if (strike==0 && ball==0) 
			{
		
				System.out.print("out");
				
				
			}
			
			if (strike == 3) 
			{
				System.out.println("성공");
				
				break;
				
			}else{
				System.out.println(ball+"ball"+":"+"strike"+strike);
				strike=0;
				ball=0;
				out=0;
			}
		}

	}
}